package com.qf.dao.impl;

import com.qf.dao.UsersDao;
import com.qf.entity.Users;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 2019/10/11
 * Administrator
 * springboot1011
 * 面向对象面向君  不负代码不负卿
 */
@Repository
public class UsersDaoImpl implements UsersDao {

    @Resource(name = "twotemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Users> getall() {
        List<Users> usersList =
                jdbcTemplate.query("select userid,username,birthday from users", new RowMapper<Users>() {
                    @Override
                    public Users mapRow(ResultSet resultSet, int i) throws SQLException {
                        Users users = new Users();
                        users.setUserid(resultSet.getInt("userid"));
                        users.setUsername(resultSet.getString("username"));
                        users.setBirthday(resultSet.getDate("birthday"));
                        return users;
                    }
                });
        return usersList;
    }

    @Override
    public List<Users> getallpage(String name) {
        return null;
    }

    @Override
    public int insertUsers(Users users) {
        return 0;
    }
}
